package http

import (
	"fmt"
	"github.com/gin-gonic/gin"
)

func SetupRouters() *gin.Engine {
	r := gin.Default()

	gokvApi := r.Group("/api")
	{
		gokvApi.POST("/put", gokvPutHandler)
		gokvApi.GET("/get", gokvGetHandler)
		gokvApi.DELETE("/delete", gokvDeleteHandler)
		gokvApi.GET("/listkeys", gokvListKeysHandler)
		gokvApi.GET("/stat", gokvStatHandler)
		gokvApi.GET("/merge", gokvMergeHandler)
		gokvApi.GET("/backup", gokvBackUpHandler)
	}
	redisApi := gokvApi.Group("/redis")
	{
		// ========= string ========== //
		redisApi.POST("/set", redisSetHandler)
		redisApi.GET("/get", redisGetHandler)

		// ========= hash ========== //
		redisApi.POST("/hset", redisHSetHandler)
		redisApi.GET("/hget", redisHGetHandler)
		redisApi.DELETE("/hdel", redisHDelHandler)
		redisApi.GET("/hexists", redisHExistsHandler)
		redisApi.GET("/hkeys", redisHKeysHandler)
		redisApi.GET("/hvals", redisHValsHandler)
		redisApi.GET("/hlen", redisHLenHandler)

		// ========= set ========== //
		redisApi.POST("/sadd", redisSAddHandler)
		redisApi.POST("/srem", redisSRemHandler)
		redisApi.GET("/smembers", redisSMembersHandler)
		redisApi.GET("/sismember", redisSIsMemberHandler)
		redisApi.GET("/scard", redisSCardHandler)

		// ========= list ========== //
		redisApi.POST("/lpush", redisLPushHandler)
		redisApi.POST("/rpush", redisRPushHandler)
		redisApi.GET("/lpop", redisLPopHandler)
		redisApi.GET("/rpop", redisRPopHandler)
		redisApi.GET("/llen", redisLLenHandler)
		redisApi.GET("/lindex", redisLIndexHandler)
		redisApi.GET("/lrange", redisLRangeHandler)

		// ========= zset ========== //
	}

	r.NoRoute(func(c *gin.Context) {
		fmt.Println("No Route", c.Request.RequestURI)
	})
	return r
}
